package cn.tedu.mintmall.controller;

import cn.tedu.mintmall.dto.SkuAddNewDTO;
import cn.tedu.mintmall.dto.SkuUpdateFullInfoDTO;
import cn.tedu.mintmall.dto.SpuUpdateDTO;
import cn.tedu.mintmall.restful.JsonResult;
import cn.tedu.mintmall.service.ISkuService;
import cn.tedu.mintmall.vo.SkuStandardVO;
import cn.tedu.mintmall.vo.SpuStandardVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sku")
@Api(tags = "sku模块")
public class SkuController {

    @Autowired
    private ISkuService skuService;

    @PostMapping("/add")
    @ApiOperation("新增sku")
    public JsonResult<Void> addNew(@Validated SkuAddNewDTO skuAddNewDTO){
        skuService.addNew(skuAddNewDTO);
        return JsonResult.ok("添加完成");
    }

    @PostMapping("/delete")
    @ApiOperation("根据id删除SKU")
    @ApiImplicitParam(value = "id",name = "skuId",required = true,dataType = "long")
    public JsonResult<Void> deleteSkuById(Long id){
        skuService.deleteSkuById(id);
        return JsonResult.ok("删除完成");
    }

    @PostMapping("/{id}/update")
    @ApiOperation("修改SKU")
    @ApiImplicitParam(value = "id",name = "skuId",required = true,dataType = "long")
    public JsonResult<Void> updateSkuById(@PathVariable("id") Long id , @Validated SkuUpdateFullInfoDTO skuUpdateFullInfoDTO){
        skuService.updateSkuById(id,skuUpdateFullInfoDTO);
        return JsonResult.ok("修改完成");
    }

    @GetMapping("/select/{id}")
    @ApiOperation("查询sku详情")
    @ApiImplicitParam(value = "id",name = "skuId",required = true,dataType = "long")
    public JsonResult<SkuStandardVO> getSpuDetailById(@PathVariable("id") Long id){
        SkuStandardVO skuStandardVO = skuService.getById(id);
        return JsonResult.ok("查询详情完成",skuStandardVO);
    }

}
